package edu.nf.project.configs;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author CSY
 * @date 2025 - 06 - 16
 * Spring Task配置类 - 用于启动定时任务功能
 */
@Configuration
//启用定时任务功能
@EnableScheduling
public class TaskConfig implements SchedulingConfigurer {
    //SchedulingConfigurer - 自定义任务调度器
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(taskExecutor());
    }

    @Bean(destroyMethod="shutdown")
    public ExecutorService taskExecutor() {
        //创建线程池大小为10，支持多任务并发执行
        return Executors.newScheduledThreadPool(10);
    }
}
